package com.analyse.stock.vo;

import cn.hutool.core.util.StrUtil;
import com.analyse.stock.enums.AnomalyTypeEnum;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.google.common.collect.Sets;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;
import java.util.Set;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class AnomalVO implements Serializable {
    /**
     * 0-资金流入异动, 1-资金流出异动，2-股价放量滞涨信号
     **/
    private String anomalyType;

    private String date;

    private String anomalyDesc;

    /**
     * 权重总和
     **/
    private Integer calcWeightVal;
    private Integer weightVal;

    public static AnomalVO me(String anomalyType,String date){
        AnomalVO vo = new AnomalVO();
        vo.date = date;
        if(StringUtils.isNotBlank(anomalyType)){
            String[] str = anomalyType.split(StrUtil.COMMA);
            Set<String> types = Sets.newHashSet();
            Set<String> descs = Sets.newHashSet();
            Integer num = 0;
            for(String s : str){
                descs.add(AnomalyTypeEnum.getDescByCode(s));
                num += AnomalyTypeEnum.getWeightByCode(s);
                types.add(s);
            }
            vo.anomalyType = String.join(StrUtil.COMMA,types);
            vo.anomalyDesc = String.join(StrUtil.COMMA,descs);
            vo.setWeightVal(num);
        }
        return vo;
    }
}
